﻿using System;
using System.Collections.Generic;
using System.Text;
using Module.Common.Models;
using Module.Core.DAO.DAO;
using Module.Core.EntitiesInfo.TablesInfo;
using System.Data;


namespace Module.Core.BusinessLogic.NewEmail
{
    public class NewEmailBL
    {
        /// <summary>
        /// Saves a record to the NewEmails table.
        /// </summary>
        public static int Insert(NewsEmailInfo emailInfo)
        {

            try
            {
                return new NewEmailDAO().Insert(emailInfo);
            }
            catch (Exception ex)
            {
                throw;
            }

        }



        /// <summary>
        /// Delete a record to the NewEmails table.
        /// </summary>
        public static void Delete(int idEmails)
        {
            try
            {
                new NewEmailDAO().Delete(idEmails);
            }
            catch (Exception ex)
            {
                throw;
            }

        }
        /// <summary>
        ///Lấy tổng số bản ghi trong bảng NewEmails
        /// </summary>
        public static int GetCount(DateTime createOnFrom, DateTime createOnTo)
        {
            try
            {
                return new NewEmailDAO().GetCount(createOnFrom, createOnTo);
            }
            catch (Exception)
            {

                throw;
            }
        }

        /// <summary>
        ///Lấy tổng số thư mới trạng thái chưa đọc
        /// </summary>
        public static int CountInbox(string email, int status)
        {
            try
            {
                return new NewEmailDAO().CountInbox(email, status);
            }
            catch (Exception)
            {

                throw;
            }
        }


        /// <summary>
        /// Lấy tổng số bản ghi
        /// </summary>
        /// <param name="beginRow">Bản ghi đầu tiên</param>
        /// <param name="endRow">Bản ghi kết thúc</param>
        /// <param name="orderByColumn">Điều kiện sắp xếp</param>       
        /// <returns></returns>
        public static DataTable Search(int beginRow, int endRow, string orderByColumn)
        {
            try
            {
                return new NewEmailDAO().Search(beginRow, endRow, orderByColumn);
            }
            catch (Exception ex)
            {
                throw;
            }

        }


        /// <summary>
        /// Lấy tổng số bản ghi
        /// </summary>        
        /// <param name="isTotalRow">=True lấy tổng sổ bản ghi</param>
        /// <returns></returns>
        public static int SelectCount(bool isTotalRow)
        {
            try
            {
                return new NewEmailDAO().SelectCount(isTotalRow);
            }
            catch (Exception ex)
            {
                throw;
            }

        }
        //Danh sách gửi mail dùng trong admin
        public static DataSet ListNewEmailPage(int idEmails, DateTime createOnFrom, DateTime createOnTo, int currPage, int recodperPage, int pageSize, int total, string link)
        {
            try
            {
                DataSet ds = new DataSet();

                ds = new NewEmailDAO().ListNewEmailPage(idEmails, createOnFrom, createOnTo, currPage, recodperPage, pageSize, total, link);
                if (ds != null)
                    return ds;
                return null;
            }
            catch (Exception ex)
            {
                throw;
            }

        }


        /// <summary>
        ///Search-ALl NewEmails
        /// </summary>
        public static DataSet Search_All(string title, string emailTransfer, DateTime createdOnFrom, DateTime createdOnTo)
        {
            try
            {
                DataSet ds = new DataSet();

                ds = new NewEmailDAO().Search_All(title, emailTransfer, createdOnFrom, createdOnTo);
                if (ds != null)
                    return ds;
                return null;
            }
            catch (Exception ex)
            {
                throw;
            }

        }
        //danh sách hộp thư đến
        public static DataSet SelectLstInbox(string email, int param)
        {
            try
            {
                DataSet ds = new DataSet();

                ds = new NewEmailDAO().SelectLstInbox(email, param);
                if (ds != null)
                    return ds;
                return null;
            }
            catch (Exception ex)
            {
                throw;
            }

        }
        //lấy chi tiết bản ghi
        public static NewsEmailInfo Select(int status)
        {
            try
            {
                return new NewEmailDAO().Select(status);
            }
            catch (Exception)
            {
            }
            return null;
        }

        //Phân trang inbox

        public static DataSet ListInbox(string email, int currPage, int recodperPage, int pageSize, int param)
        {
            try
            {
                DataSet ds = new DataSet();

                ds = new NewEmailDAO().ListInbox(email, currPage, recodperPage, pageSize, param);
                if (ds != null)
                    return ds;
                return null;
            }
            catch (Exception ex)
            {
                throw;
            }

        }
        //chi tiết thư
        public static NewsEmailInfo DetailsInbox(int idEmail, string email, int param)
        {
            try
            {
                return new NewEmailDAO().DetailsInbox(idEmail, email, param);
            }
            catch (Exception)
            {
            }
            return null;
        }

        /// <summary>
        /// Cập nhật status khi thành viên đọc thư
        /// status=1-> -Thư chưa đọc
        /// status=2  -Thư đã đọc
        /// 
        /// </summary>

        public static void UpdateStatus(int idEmails, int status)
        {
            try
            {
                new NewEmailDAO().UpdateStatus(idEmails, status);
            }
            catch (Exception ex)
            {
                throw;
            }

        }

        //Reply EMail
        public static NewsEmailInfo ReplyEmail(int idEmails)
        {
            try
            {
                return new NewEmailDAO().ReplyEmail(idEmails);
            }
            catch (Exception)
            {
            }
            return null;
        }
    }
}